import 'package:flutter/material.dart';

class Page1 extends StatelessWidget {
  const Page1({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('页面1'),
      ),
      body: Center(
        child: ElevatedButton(
          child: Text('跳转'),
          //路由跳转方法  onPressed: () {
          //   Navigator.of(context).push(MaterialPageRoute(
          //     builder: (context) {
          //       return Page2();
          //     },
          //       settings: RouteSettings(
          //         name: 'menu',
          //         arguments: ''
          //       ),
          //     maintainState: false,
          //     fullscreenDialog: true
          //   ));
          // },

          // //异步操作-组件传参
          // onPressed: () async {
          //   var result = await Navigator.of(context).push(MaterialPageRoute(
          //       builder: (context) {
          //         return Page2(pageTitle: '菜单');
          //       },
          //       settings: RouteSettings(name: 'menu', arguments: ''),
          //       maintainState: false,
          //       fullscreenDialog: true));
          //   print('打印接收返回参数==========');
          //
          //   print(result);
          // },

          onPressed: () {
            Navigator.of(context)
                .push(MaterialPageRoute(
                    builder: (context) {
                      return Page2(pageTitle: '菜单');
                    },
                    settings: RouteSettings(name: 'menu', arguments: {"name":'12123',"like":"23333"}),
                    maintainState: false,
                    fullscreenDialog: false))
                .then((value) => print(value));
          },
        ),
      ),
    );
  }
}

class Page2 extends StatelessWidget {
  final String pageTitle;

  const Page2({Key? key, required this.pageTitle}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    dynamic arguments = ModalRoute.of(context)!.settings.arguments.toString();
    print(arguments);
    return Scaffold(
      appBar: AppBar(
        title: Text(pageTitle),
      ),
      body: Center(
        child: ElevatedButton(
          child: Text(arguments),
          onPressed: () {
            //'齐安郡晚秋'
            //{"name": '齐安郡晚秋'}
            Navigator.of(context).pop({"name": '返回值=齐安郡晚秋'});
          },
        ),
      ),
    );
  }
}
